//
// Created by hunan on 25-3-1.
//
#include <gtest/gtest.h>
#include <cstring>
#include "loop_module/loop.h"
#include "string_util/string_util.h"
#include "socket_module/udp_socket_connection.h"

TEST(TestPrint, Test)
{
    printf("Hello");
}

TEST(UdpTest, Stun)
{
    Loop loop;
    auto connection = std::make_shared<UdpSocketConnection>(&loop);
    std::string                domain     = "stun.l.google.com";
    std::string                protocol   = "19302";
    std::vector<SocketAddress> socket_address;
    SocketAddress::UdpAddress(domain, atoi(protocol.c_str()), socket_address);
    if (socket_address.empty())
    {
        ASSERT_EQ(true, false);
    }
    std::string packet = "000100002112a442cda344c6ffa066d311b63dac";
    const char * ptr   = packet.c_str();
    std::vector<uint8_t> packet_data;
    StringUtil::HexStrToCharacter(ptr, packet_data);
    connection->OpenSocket({}, {});
    int ret = connection->AsyncWrite(packet_data.data(), packet_data.size(), *socket_address.data());
    connection->SetOnRead([](auto conn, int result, auto message) {

        printf("recv message.\n");
    });
    printf("write ret : %d.\n", ret);
    loop.Run();
}